package com.rxyl.love.petdoctor.adapter;

import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.rxyl.love.petdoctor.R;
import com.rxyl.love.petdoctor.entity.TopicEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zuchang on 2016/1/21.
 */
public class TopicAdatper<T> extends BaseAdapter {
    private Context context;
    private List<T> datas;

    public TopicAdatper(Context context,List<T> datas){
        this.datas = datas;
        this.context=context;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TopicEntity.Items entity = (TopicEntity.Items) datas.get(position);
        ViewHodler viewHodler;
        if(convertView==null){
            convertView = View.inflate(context,R.layout.topic_detail,null);
            viewHodler = new ViewHodler();
            viewHodler.im_topic = (SimpleDraweeView) convertView.findViewById(R.id.iv_topic);
            viewHodler.tv_topicname = (TextView) convertView.findViewById(R.id.tv_topicname);
            viewHodler.tv_description = (TextView) convertView.findViewById(R.id.tv_description);
            convertView.setTag(viewHodler);
        }else {
            viewHodler = (ViewHodler) convertView.getTag();
        }
        viewHodler.tv_topicname.setText("#"+entity.getName()+"#");
        viewHodler.tv_description.setText(entity.getDescription());

        String icon_uri = entity.getIcon_url();
        Log.d("logdd", icon_uri);
        if(icon_uri!=null){
          viewHodler.im_topic.setImageURI(Uri.parse(icon_uri));
        }else{
            viewHodler.im_topic.setImageURI(Uri.parse(""));
        }


        return convertView;
    }


    class ViewHodler{
        private SimpleDraweeView im_topic;
        private TextView tv_topicname,tv_description;
    }
}
